﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using DataLib.Common;
using DataLib.Accounts.Bus;

namespace Ewts.BaseData
{
    public partial class PlateNumberAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ListItem item = new ListItem();
                item.Text = "--请选择--";
                item.Value = "";
                DataTable dt = new DataLib.BLL.TransportCompany().GetList("").Tables[0];
                ddltransportIid.DataSource = dt;
                ddltransportIid.DataTextField = "companyname";
                ddltransportIid.DataValueField = "id";
                ddltransportIid.DataBind();
                ddltransportIid.Items.Insert(0, item);

                dropCity.DataSource = new DataLib.BLL.City().GetList("flag1='02'").Tables[0];
                dropCity.DataTextField = "cityname";
                dropCity.DataValueField = "citycode";
                dropCity.DataBind();
                dropCity.Items.Insert(0, item);
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtplateno.Text.Trim().Length == 0)
            {
                strErr += "车牌号不能为空！\\n";
            }
            if (this.ddltransportIid.SelectedValue == "")
            {
                strErr += "请选择运输公司！\\n";
            }
            if (this.dropCity.SelectedValue == "")
            {
                strErr += "请选择归属地！\\n";
            }           

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int transportIid = int.Parse(this.ddltransportIid.SelectedValue);
            string city = dropCity.SelectedItem.Text;
            string vehicletype = this.txtvehicletype.Text;
            string plateno = this.txtplateno.Text;
            decimal maxton = 0;
            if(txtmaxton.Text.Trim()!="")
                maxton = decimal.Parse(this.txtmaxton.Text);

            DataLib.Model.PlateNumber model = new DataLib.Model.PlateNumber();
            model.transportIid = transportIid;
            model.city = city;
            model.vehicletype = vehicletype;
            model.plateno = plateno;
            model.maxton = maxton;

            DataLib.BLL.PlateNumber bll = new DataLib.BLL.PlateNumber();
            bll.Add(model);
            DataLib.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "PlateNumberAdd.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("PlateNumberList.aspx");
        }
    }
}